package com.hspedu.mhl.service;

import com.hspedu.mhl.dao.BillDao;
import com.hspedu.mhl.dao.MultiTableDao;
import com.hspedu.mhl.domain.Bill;
import com.hspedu.mhl.domain.Court;
import com.hspedu.mhl.domain.MultiTableBean;

import java.util.List;
import java.util.UUID;

public class BillService {
    private BillDao billDao = new BillDao();
    CompanionsService companionsService = new CompanionsService();
    CourtTableService courtTableService = new CourtTableService();
    MultiTableDao multiTableDao = new MultiTableDao();

    //1.生成账单
    //2.更新对应的餐桌状态
    public boolean orderBill(int companion_id, int nums, int court_id) {
        String billId = UUID.randomUUID().toString();

        int update = billDao.update("insert into bill values(null,?,?,?,?,?,now(),'未结账')", billId, companion_id,
                companionsService.getCompanionsmoney(companion_id), nums, court_id);

        if (update <= 0) {
            return false;
        }

        //更新场地信息
        return courtTableService.Com_Court(court_id, "与同伴对打中");
    }

    public List<Bill> getBillList() {
        List<Bill> bills = billDao.queryMulti("select *from bill", Bill.class);
        return bills;
    }

    public List<MultiTableBean> getBillList1() {
        return multiTableDao.queryMulti("select bill.*,NAME from bill,companions where bill.id=companions.id",
                MultiTableBean.class);
    }
}
